/**
 * Created by admin on 2017/9/4.
 */
define(['app', 'filters/filters'], function(app) {
    app.register.controller('reportDetail',['$scope','$state','$stateParams','$rootScope','$Ajax','$http', function($scope, $state, $stateParams, $rootScope,$Ajax,$http) {
        var http = app._baseUrl;
        $scope.ability_check_id = $stateParams.ability_check_id;
        $scope.type = $stateParams.type;
        $scope.load = {
            _getInitial: function() { //个人报告详情
                if($scope.type == 1){
                    var url = http + '/My/MyAbility/abilityReportInfo';
                }else{
                    var url = http + '/QyManage/AbilityCheck/abilityReportInfo';
                }
                var data = {
                    ability_check_id:$scope.ability_check_id
                };
                $Ajax.postData(url,data,$scope).then(function(res){
                    if(res.data.success){
                        $scope.user_info = res.data.data.user_info;
                        $scope.second_ability_list = res.data.data.second_ability_list;
                        $scope.third_ability_list = res.data.data.third_ability_list;
                        $scope.average = res.data.data.average;
                        $scope.bad = res.data.data.bad;
                        $scope.mature_list = res.data.data.mature_list;
                        // $scope.mature_list =  {
                        //     "zw": "调用-店铺运营能力，调用-商品运营能力",
                        //     "sx": "调用-商品运营能力",
                        //     "lj":"调用-商品运营能力",
                        //     "br":"调用-商品运营能力",
                        // };
                    }

                });

            },
            init: function() {
                this._getInitial && this._getInitial();
            }
        };
        $scope.load.init && $scope.load.init();

    //    to_top返回顶部
        $scope.top = function(){
            $("html,body").animate({scrollTop:0},1000);
        }

    //    下载png
        $scope.down_img = {
            width:document.body.scrollWidth,
            height:document.body.scrollHeight,
            btn:document.getElementById('download_btn'),
            btn_click:function(){
                this.onclick();
            },
            onclick:function(){
                html2canvas($("#report_page"),{
                    onrendered: function(canvas) {
                        document.body.appendChild(canvas);
                        var canvas = document.getElementsByTagName('canvas')[0];
                        url = canvas.toDataURL();
                        //以下代码为下载此图片功能
                        var triggerDownload = $("<a>").attr("href", url).attr("download", "img.png").appendTo("body");
                        triggerDownload[0].click();
                        triggerDownload.remove();
                        document.body.removeChild(canvas);
                    },
                    width:this.width,
                    height:this.height
                });
            }
        };
    //    鼠标滚动二级分数条动
        $scope.isWidth = true;
        var arr = [];
        var progressBar = document.getElementsByClassName('progressBar');
        document.body.addEventListener('DOMMouseScroll',function(e){

        });
        document.body.addEventListener('mousewheel',function(e){
            if($scope.isWidth){
                angular.forEach(progressBar,function(item,index,data){
                    var obj = {
                        width:item.offsetWidth
                    };
                    arr.push(obj);
                });
                $scope.isWidth = false;
            }
           if($(this).scrollTop() > 150){
               $('.report_page #progressBar').width('0');
               angular.forEach(progressBar,function(item,index,data){
                   $(item).animate({'width':arr[index].width},3000);
               });
           }
        })
    }])
})